<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/21
 * Time: 14:47
 */
namespace app\api\controller\v1;
use think\Db;

class Order extends Base {
    public function _initialize(){
        parent::_initialize();
    }
    //购买具体业务
    public function makeOrder(){
        if($this->request->isPost()){
            $post = input('post.');
            //验证是否登录
            $this->isLogin($post);
            $uid = isset($post['uid'])? ($post['uid']):'';
            $total_price = isset($post['total_price'])? ($post['total_price']):'';
            if(empty($uid)) return show(400,'用户ID不能为空');
            if(empty($total_price)) return show(400,'金额不能为空');
            $post['create_time'] = time();
            $post['out_trade_no'] = 'qnn'.date('ymdHis').uniqid();
            //金币订单表
            $res = Db::name('Order')->insert($post);
            if(!$res){
                return show(400,'订单生成失败');
            }
            $data['out_trade_no'] = $post['out_trade_no'];
            $data['uid'] = $post['uid'];
            return show(200,'订单生成成功',$data);


        }

    }
}